<template>
    <div class="login-wrapper">
        <div class="login-panel">
<h1>西洲医院一体化智慧中心</h1>
            <el-form
        ref="ruleFormRef"
    :model="ruleForm"
    :rules="rules"
    label-width="80px"
    class="demo-ruleForm"
    size="default"
    status-icon>
    <el-form-item label="用户名" prop="account">
      <el-input v-model="ruleForm.account" />
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input v-model="ruleForm.password" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        Login
      </el-button>
      <el-button @click="resetForm(ruleFormRef)">Reset</el-button>
    </el-form-item>

</el-form>
        </div>
        
    </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { ElMessage, } from 'element-plus' 


const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive({
    account:'',
    password:''
  
})

const rules = reactive<FormRules>({
    account: [
    { required: true, message: '请输入账号', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 1, max: 15, message: 'Length should be 1 to 15', trigger: 'blur' },
  ],
  
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!')
      console.log(ruleForm);
      success(ruleForm)
    //   success()
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

const store=useStore()
const router = useRouter()

//登录
const success = async (data) => {
        // console.log(store.state.ljh.name)
        console.log(data);
        const res = await store.dispatch("ljh/A_login", data)
        console.log(res);
        if(res.data.code===1){
            ElMessage.success('登录成功了')
            router.push('/home')
        }else{
            ElMessage.error(res.data.msg)

        }
        
    }
</script>

<style scoped lang="scss">
    .login-wrapper{
        width: 100%;
        height: 100%;
        // background: va'r(--base-color);
        background: url('@/assets/img/ganyu.png') no-repeat center;
        background-size: 100%;
        .login-panel{
            width: 500px;
            height: 250px;
            margin: auto;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            border-radius: 10px;
            border: 1px solid #8ea8ea;
            padding: 20px;
            text-align: center;
            background: rgba(255,255,255,.8);
           .el-form-item{
            margin: 28px 0 ;
           }
        }
    }
</style>